package com.cleargroup.magic.cleara.c.command;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;

import java.util.List;

public class StatusCommand implements ICommand/*, IStatusCommandListener*/{
	public static final String TAG = StatusCommand.class.getSimpleName();
	public static final int INTERVAL = 10 * 60 * 1000;

	private static PendingIntent intent;
	private static StatusCommand instance;
	private Context context;

	private StatusCommand(Context context) {
		this.context = context;
	}

	public static StatusCommand getInstance(Context context) {
		if (instance == null) {
			instance = new StatusCommand(context);
		}
		return instance;
	}

	public static PendingIntent getBroadcast(Context context) {
		if (intent == null) {
			intent = PendingIntent.getBroadcast(context, 0, new Intent(
					COMMAND_UPDATE_STATUS), 0);
		}
		return intent;
	}

	public void execute(List... lists) {
	}

	public void startAlarm() {
		AlarmManager am = (AlarmManager) context
				.getSystemService(Service.ALARM_SERVICE);
		am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),
				INTERVAL, StatusCommand.getBroadcast(context));
	}

	public void stopAlarm() {
		PendingIntent i = StatusCommand.getBroadcast(context);
		AlarmManager am = (AlarmManager) context
				.getSystemService(Service.ALARM_SERVICE);
		am.cancel(i);
	}

}
